package com.haiqi.modules.ship.service;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.dao.CommunicationInfoMapper;
import com.haiqi.common.persistence.entity.CommunicationInfo;
import com.haiqi.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by hythzx on 2016/5/26.
 * 通联信息
 */
@Service
public class ShipCommunicationInfoService {

    @Autowired
    private CommunicationInfoMapper communicationInfoMapper;

    public PageInfo<CommunicationInfo> getDataList(CommunicationInfo communicationInfo,PageBean page){
        PageUtils.generatePage(page);
        List<CommunicationInfo> dataList = communicationInfoMapper.getDataList(communicationInfo);
        PageInfo<CommunicationInfo> communicationInfoPageInfo = new PageInfo<>(dataList);
        return communicationInfoPageInfo;
    }

    public List<CommunicationInfo> getDataList(CommunicationInfo communicationInfo){
        List<CommunicationInfo> dataList = communicationInfoMapper.getDataList(communicationInfo);
        return dataList;
    }

    public CommunicationInfo getCommunicationInfo(int id){
        CommunicationInfo communicationInfo = communicationInfoMapper.selectByPrimaryKey(id);
        return communicationInfo;
    }

    public boolean update(CommunicationInfo communicationInfo){
        boolean success = false;
        int count = 0;
        if(communicationInfo.getId() == null){
            count = communicationInfoMapper.insert(communicationInfo);
        }else{
            count = communicationInfoMapper.updateByPrimaryKeySelective(communicationInfo);
        }
        if(count > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(int id){
        boolean success = false;
        int count = 0;
        count = communicationInfoMapper.deleteByPrimaryKey(id);
        if(count > 0){
            success = true;
        }
        return success;
    }
}
